<template>
  <div><page-list :x-uri="uri" :x-tabs="tabs" :doactions="doactions">
    <!-- 多选操作 -->
    <template v-slot:table-button="scope">
      <el-button v-auth="'sns.circle.comment.delete'" size="mini" @click="deletes(scope)">删除</el-button>
    </template>
  </page-list></div>
</template>

<script>
import PageList from '@public/template/page_list.vue';
export default {
  components: {
    PageList
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/circle/admin/' + this.$route.params.id + '/comment/list',
      tabs: [
        {
          title: '学友圈',
          uri: '/sns/circle/list',
          meta: {
            permission: 'sns.circle.list'
          }
        },
        {
          title: '学友圈- 动态评论',
          uri: '/sns/circle/' + this.$route.params.id + '/comment',
          meta: {
            permission: 'sns.circle.comment.list'
          }
        }
      ],
      doactions: [
        { title: '删除', meta: { permission: 'sns.circle.comment.delete' }, callback: this.delete }
      ]
    };
  },
  methods: {
    delete: function({ row }) {
      this.$box
          .confirm('确认删除吗')
          .then(() => {
            this.$http.delete(
                '/circle/admin/comment/' + row.id + '/delete',
                {},
                response => {
                  this.$message.success(response.msg, _ => {
                    this.reload();
                  });
                },
                error => {
                  this.$message.error(error.msg);
                }
            );
          })
          .catch(() => {});
    },
    // 批量删除
    deletes: function({ rows }) {
      var ids = rows.map(row => row.id);
      if (ids.length === 0) {
        this.$message.warning('请选择要删除的评论');
        return false;
      }
      ids = ids.join(',');
      this.$box
          .confirm('确认删除吗')
          .then(() => {
            this.$http.delete(
                '/circle/admin/comment/deletes/' + ids,
                {},
                response => {
                  this.$message.success(response.msg, _ => {
                    this.reload();
                  });
                },
                error => {
                  this.$message.error(error.msg);
                }
            );
          })
          .catch(() => {});
    }
  }
};
</script>
